﻿// Write a program that fills and prints a matrix of size (n, n) / Point B

using System;

class PrintMatrixPointB
{
    static void Main()
    {
        // read from console
        Console.Write("Enter Matrix size (n): ");
        int size = int.Parse(Console.ReadLine());

        int[,] matrix = new int[size, size];
        int iterator = 1;
        for (int col = 0; col < matrix.GetLength(1); col++)
        {
            for (int row = 0; row < matrix.GetLength(0); row++)
            {
                if ((col + 1) % 2 == 0)
                {
                    // reverse row number if col is even
                    int rowReverse = matrix.GetLength(1) - row - 1;
                    matrix[rowReverse, col] = iterator;
                }
                else
                {
                    matrix[row, col] = iterator;
                }
                iterator++;
            }
        }

        // print matrix
        for (int row = 0; row < matrix.GetLength(0); row++)
        {
            for (int col = 0; col < matrix.GetLength(1); col++)
            {
                Console.Write("{0, 4}", matrix[row, col]);
                if (row != matrix.GetLength(0) - 1 || col != matrix.GetLength(1) - 1)
                {
                    Console.Write(", ");
                }
            }
            Console.WriteLine();
        }
    }
}